package com.googlecode.nacl_optimizer.model;

import java.util.List;

/**
 * Model of procedure (as sequence of `block's)
 * 
 * @author kornevgen
 */
public class Procedure
{
	protected final List<Block> blocks;
	private final String name;
	private final String startAddr;
	
	public Procedure( List<Block> blocks, String name, String startAddr )
	{
		this.blocks = blocks;
		this.name = name;
		this.startAddr = startAddr;
	}
	
	public List<Block> getBlocks()
	{
		return blocks;
	}
	
    public Instruction search_by_label(String target)
    {
        for( Block b : blocks )
        {
            for( Instruction i: b.instructions )
            {
                if ( i.getLabel().equals(target) )
                    return i;
            }
        }
        throw new IndexOutOfBoundsException("internal error with label searching");
    }

    public String getName()
    {
        return name;
    }

    public String getStartAddr()
    {
        return startAddr;
    }

}
